package mypractice;

public class Leetcode383 {
    public static void main(String[] args) {
        String ransomNote="fihjjjjei";
        String magazine="hjibagacbhadfaefdjaeaebgi";
        System.out.println(canConstruct(ransomNote,magazine));
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        int ranLen = ransomNote.length();
        int magLen=magazine.length();
        int[] countRan=new int[26];
        int[] countMag=new int[26];
        int i;
        for(i=0;i<ranLen;i++)
        {
            countRan[ransomNote.charAt(i)-'a']++;
        }
        for(i=0;i<magLen;i++)
        {
            countMag[magazine.charAt(i)-'a']++;
        }
        for(i=0;i<26;i++){
            if(countMag[i]>=countRan[i]){
                continue;
            }else{
                return false;
            }
        }
        return true;
    }
}
